<script>

var chk = "";

function addCheck(val,obj)
{
	chk = chk + val + ";";
	
	if(!$(obj).attr("checked"))
			alert(chk.replace(val+";",""));
	
}

function saveIngred()
{
	if(!chk)
	{
		msg({vmsg: "Nenhum ingrediente selecionado."});

		return false;
	}
	
	$.post("product/saveingred", {chk: chk, ped: auxPedido}, function(){
		msg({vmsg: "Ingrediente Salvo.",time: 3000});
	});
}

$(function(){
	$(".sort").tablesorter({widgets: ['zebra']});
});
</script>

<div class="blk_screen" style="opacity: 0.8; position: fixed; z-index: 999; width: 100%; height: 100%; background-color: white; top: 0; left: 0;"></div>
<div id="ingred_all">
	<div class="ui-corner-all" style="padding: 10px; border: 1px solid gray; background: white; position: absolute; z-index: 1000; top: 30px; left: 50%; margin-left: -250px; width: 500px;">
		<div style="font-size: 22px; color: gray; text-align: left;">
			Selecione os ingredientes a serem excluidos
		</div>
		<hr style="border-top: 1px dashed gray; margin-top: 5px; margin-bottom: 5px;" />
		<form class="frm">
			<table class="sort" width="100%" cellspacing="1" cellpadding="5" style="font-size: 15px;">
				<thead>
					<tr>
						<th style="background: #dfdfdf;">
						</th>
						<th>Ingrediente</th>
					</tr>
				</thead>
				<tbody>
					<?php 
					foreach ($this->arr_ingred as $key => $val)
					{
					?>
					<tr onclick="$('#ch'+'<?php echo $val["caf07_cod"]; ?>').click();" >
						<td width="1%">
							<input id="ch<?php echo $val["caf07_cod"]; ?>" type="checkbox" <?php if($val["caf08_cod_ing"])echo "checked=checked";?> name="caf07_cod" onclick="addCheck(<?php echo $val["caf07_cod"]; ?>, this);" value="<?php echo $val["caf07_cod"]; ?>" />
						</td>
						<td>
							<?php echo $val["caf07_ingred"]; ?>
						</td>
					</tr>
					<?php 
					}
					?>
				</tbody>
			</table>
		</form>
		<?php if(!$this->arr_ingred){?>
			<i>Nenhum ingrediente disponivel.</i>
			<script>
				$(function(){
					$("#salvar_btn").click(function(){
						$('.blk_screen').hide(); $('#ingred_all').hide();
					});
				});
			</script>
		<?php }?>
		<hr style="margin: 10px 0 10px 0;" />
		<div>
			<div id="salvar_btn" class="button ui-corner-all" onclick="saveIngred(); $('#ingred_all').hide(); $('.blk_screen').hide();" style="text-align: center; float: left; padding: 20px; width: 201px;">
				<b>Salvar</b>
			</div>
			<div class="button ui-corner-all" onclick="$('.blk_screen').hide(); $('#ingred_all').hide();" style="text-align: center; padding: 20px; margin-left: 256px; width: 201px;">
				<b>Cancelar</b>
			</div>
		</div>
	</div>
</div>